package controllers;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import client.CcrmApp;
import model.Envelope;
import view.AreaGui;

/** This Class is a Area Controller which extends AbstractTransfer
 * 
 * @author jacob
 */

public class AreaController extends AbstractTransfer{

	private MarketingManagController prevCon;
	private AreaGui AreaView;

	private AreaController curCont;
/**
 * this is Area Controller contractor
 * @param ar is Area Gui instance
 * @param lastCont is the prev controller instance
 */

	public AreaController(AreaGui ar,MarketingManagController lastCont){
		AreaView = ar;
		prevCon = lastCont;
		curCont = this;
		AreaView.addAddActionListener(new addListener());
		AreaView.addBackActionListener(new backListener());
	}
	/**
	 * Inner class that handles when Button Add Pressed, implements ActiontListener
	 * @author jacob
	 *
	 */
	
	class addListener implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) {
			// TODO Auto-generated method stub
			try{ //get the text from Text from JTextField and send to server to check if to add or return that exist
				AreaView.setWarningMesFalse();
				String que = AreaView.getText();
				if(que.equals("") != true){
				String que1 = "add area";
				Envelope ev1 = new Envelope(que,que1);

				sendToServer(ev1);	
				CcrmApp.clien.setCurrObj(getCurCont());
			    }
				}
				  catch(Exception e1){
					  
				  }
			
		}
	}
	
	/**
	 * Inner class that handles when Button back Pressed, implements ActiontListener
	 * @author jacob
	 *
	 */
	
	class backListener implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) {
			// TODO Auto-generated method stub
			//dispose the current Gui and show the prev Gui 
			AreaView.dispose(); 
			prevCon.getMarkGui().setVisible(true);
			
		}
	}
	/**
	 * get the current controller 
	 * @return AreaController
	 */
	public AreaController getCurCont() {
		return curCont;
	}
	
	/**
	 * get the Area View Gui
	 * @return AreaGui
	 */
	public AreaGui getAreaView() {
		return AreaView;
	}

}
